package com.xzy.controller;

import com.xzy.entity.Book;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

/**
 * desc：
 *
 * @author xzy.xiao
 * @date 2022/3/23  14:43
 */
@Slf4j
@Controller
@RequestMapping(path = "/test")
public class TestController {

    /**
     * hello world!
     */
    @GetMapping(path = "/hello_world")
    public String helloWorld(ModelMap modelMap) {
        Map<String, Object> hi = new HashMap<>(2);
        hi.put("uuid", UUID.randomUUID().toString());
        hi.put("timestamp", System.currentTimeMillis());
        modelMap.put("hi", hi);
        return "test/helloworld";
    }

    /**
     * list指令
     */
    @GetMapping(path = "/list")
    public String dataTree(ModelMap modelMap) {
        Map<String, Object> authors = new HashMap<>(3);
        authors.put("儒勒·凡尔纳", Arrays.asList(
                new Book("《格兰特船长的儿女》", 199.0),
                new Book("《海底两万里》", 99.0),
                new Book("《地心游记》", 99.0),
                new Book("《神秘岛》", 49.0))
        );
        authors.put("丹尼尔·笛福", Arrays.asList(
                new Book("《鲁滨逊漂流记》", 299.0),
                new Book("《骑士回忆录》", 98.0))
        );
        authors.put("王五", Arrays.asList(
                new Book("《Java从入门到入土》", 199.0),
                new Book("《深入理解JVM》", 99.0),
                new Book("《Java并发编程》", 49.0))
        );

        modelMap.put("authors", authors);
        return "test/list";
    }

}
